// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const testPart = db.collection('testPart')

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const testCnt = testPart.doc('testCnt')

  testCnt.update({
    data: {
      num: db.command.inc(1)
    }
  })

  let temp = -1
  testCnt.get().then(res => {
    console.log(res.data)
    temp = res.data
    return {
      event,
      openid: wxContext.OPENID,
      appid: wxContext.APPID,
      unionid: wxContext.UNIONID,
      num: temp
    }
  })
}